﻿using System.Security.Cryptography;
using System.Text;
using Nancy;

namespace BLWCMS.Web.Include
{
    public class MachineKey:NancyModule
    {
        public MachineKey()
        {
            Get["/tools/machinekey"] = p => GetMachineKey();
        }

        private string GetMachineKey()
        {
            return "validationKey：" + CreateKey(20) + "    decryptionKey：" + CreateKey(24);
        }

        private string CreateKey(int len)
        {
            byte[] bytes = new byte[len];
            new RNGCryptoServiceProvider().GetBytes(bytes);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < bytes.Length; i++)
            {
                sb.Append(string.Format("{0:X2}", bytes[i]));
            }
            return sb.ToString();
        }
    }
}